From 684a085311ee4a6eb82fce7650b7354f9aa900a3 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 13 Apr 2005 03:20:36 +0000 Subject: [PATCH] Let shortname generator have access to full waypoint in case it wants to use extra fields in the decision-making process. Not all formats or callers converted yet. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1137 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/Makefile | 8 ++++---- gpsbabel/cetus.c | 2 +- gpsbabel/csv_util.c | 4 ++-- gpsbabel/defs.h | 3 ++- gpsbabel/gpsutil.c | 2 +- gpsbabel/gpx.c | 10 +--------- gpsbabel/html.c | 2 +- gpsbabel/lowranceusr.c | 2 +- gpsbabel/magnav.c | 2 +- gpsbabel/magproto.c | 4 ++-- gpsbabel/mapsend.c | 2 +- gpsbabel/mkshort.c | 42 ++++++++++++++++++++++++++---------------- gpsbabel/ozi.c | 2 +- gpsbabel/palmdoc.c | 6 +++--- gpsbabel/pcx.c | 2 +- gpsbabel/psp.c | 2 +- gpsbabel/text.c | 2 +- gpsbabel/tmpro.c | 2 +- gpsbabel/tpg.c | 2 +- 19 files changed, 52 insertions(+), 49 deletions(-) diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index e74ab2f58..600221e8a 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -90,10 +90,10 @@ dep: (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > internal_styles.c || (rm -f internal_styles.c ; exit 1)' ) >> /tmp/dep echo Edit Makefile and bring in /tmp/dep -VERSIONU=1_2_5_beta03272005-c -VERSIOND=1.2.5_beta03272005-c -VERSIONU=1_2_5 -VERSIOND=1.2.5 +VERSIONU=1_2_6-beta04122005-gsak +VERSIOND=1.2.6_beta04122005-gsak +# VERSIONU=1_2_5 +# VERSIOND=1.2.5 release: cvs commit diff --git a/gpsbabel/cetus.c b/gpsbabel/cetus.c index 17927d013..6b09650d0 100644 --- a/gpsbabel/cetus.c +++ b/gpsbabel/cetus.c @@ -397,7 +397,7 @@ data_write(void) if (global_opts.synthesize_shortnames && waypointp->description) { if (waypointp->shortname) xfree(waypointp->shortname); - waypointp->shortname = mkshort(mkshort_wr_handle, waypointp->description); + waypointp->shortname = mkshort_from_wpt(mkshort_wr_handle, waypointp); } bh->wpt_name = waypointp->shortname; bh ++; diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index 42d67b985..02cb3ebf8 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -854,8 +854,8 @@ xcsv_waypt_pr(const waypoint *wpt) if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { - if (global_opts.synthesize_shortnames) - shortname = mkshort(xcsv_file.mkshort_handle, wpt->description); + if (global_opts.synthesize_shortnames) + shortname = mkshort_from_wpt(xcsv_file.mkshort_handle, wpt); else shortname = csv_stringclean(wpt->description, xcsv_file.badchars); } else { diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index e979c6d86..c3e9b54dc 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002, 2003, 2004, 2005 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -330,6 +330,7 @@ void *MKSHORT_NEW_HANDLE(DEBUG_PARAMS); #define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__) #define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__) #endif +char *mkshort_from_wpt(void *h, const waypoint *wpt); void mkshort_del_handle(void *h); void setshort_length(void *, int n); void setshort_badchars(void *, const char *); diff --git a/gpsbabel/gpsutil.c b/gpsbabel/gpsutil.c index 4433a7fa1..ae648d093 100644 --- a/gpsbabel/gpsutil.c +++ b/gpsbabel/gpsutil.c @@ -118,7 +118,7 @@ gpsutil_disp(const waypoint *wpt) fprintf(file_out, "%-8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n", global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, wpt->description) : + mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, fabs(lat), lat < 0.0 ? 'S' : 'N', diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 1eb5d7021..9450e2a59 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -52,7 +52,6 @@ static int input_string_len = 0; static time_t file_time; -static char *gsshortnames = NULL; static char *snlen = NULL; static char *suppresswhite = NULL; static char *urlbase = NULL; @@ -658,11 +657,7 @@ gpx_end(void *data, const char *el) wpt_tmp = NULL; break; case tt_cache_name: - if (gsshortnames) { - if (wpt_tmp->notes) - xfree(wpt_tmp->notes); - wpt_tmp->notes = xstrdup(cdatastrp); - } + wpt_tmp->notes = xstrdup(cdatastrp); break; case tt_cache_container: wpt_tmp->gc_data.container = gs_mkcont(cdatastrp); @@ -1321,9 +1316,6 @@ gpx_write(void) static arglist_t gpx_args[] = { - { "gsshortnames", &gsshortnames, - "Prefer shorter descriptions from Groundspeak files", - NULL, ARGTYPE_BOOL }, { "snlen", &snlen, "Length of generated shortnames", NULL, ARGTYPE_INT }, { "suppresswhite", &suppresswhite, diff --git a/gpsbabel/html.c b/gpsbabel/html.c index 1f61d3966..0b4c5dcbf 100644 --- a/gpsbabel/html.c +++ b/gpsbabel/html.c @@ -83,7 +83,7 @@ html_disp(const waypoint *wpt) fprintf(file_out, "
\n"); fprintf(file_out, "
\n", wpt->shortname); fprintf(file_out, "

%s - %c%d°%06.3f %c%d°%06.3f (%ld%c %6.0f %7.0f)", - (global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname, + (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, wpt->latitude < 0 ? 'S' : 'N', latint, 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', lonint, 60.0 * (fabs(wpt->longitude) - lonint), utmz, utmzc, utme, utmn); diff --git a/gpsbabel/lowranceusr.c b/gpsbabel/lowranceusr.c index e0fac3c95..12b78e375 100644 --- a/gpsbabel/lowranceusr.c +++ b/gpsbabel/lowranceusr.c @@ -300,7 +300,7 @@ lowranceusr_waypt_pr(const waypoint *wpt) /* Try and make sure we have a name */ if ((! wpt->shortname) || global_opts.synthesize_shortnames) { if (wpt->description && global_opts.synthesize_shortnames) { - name = mkshort(mkshort_handle, wpt->description); + name = mkshort_from_wpt(mkshort_handle, wpt); } else if (wpt->shortname) { name = xstrdup(wpt->shortname); } else if (wpt->description) { diff --git a/gpsbabel/magnav.c b/gpsbabel/magnav.c index bc0a8183a..8e9370dc9 100644 --- a/gpsbabel/magnav.c +++ b/gpsbabel/magnav.c @@ -145,7 +145,7 @@ my_writewpt(const waypoint *wpt) char *vdata; time_t tm_t; const char *sn = global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, wpt->description) : + mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname; rec = xcalloc(sizeof(*rec)+56,1); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 2141314cd..c094c68a5 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -1168,7 +1168,7 @@ mag_waypt_pr(const waypoint *waypointp) const char *icon_token=NULL; char *owpt; char *odesc; - char *isrc; + char *isrc = NULL; ilat = waypointp->latitude; ilon = waypointp->longitude; @@ -1197,7 +1197,7 @@ mag_waypt_pr(const waypoint *waypointp) isrc = waypointp->notes ? waypointp->notes : waypointp->description; owpt = global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, isrc) : waypointp->shortname; + mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; odesc = isrc ? isrc : ""; owpt = mag_cleanse(owpt); diff --git a/gpsbabel/mapsend.c b/gpsbabel/mapsend.c index 0a7062337..fa538c342 100644 --- a/gpsbabel/mapsend.c +++ b/gpsbabel/mapsend.c @@ -316,7 +316,7 @@ mapsend_waypt_pr(const waypoint *waypointp) static int cnt = 0; const char *iconp = NULL; const char *sn = global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, waypointp->description) : + mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; char *tmp; diff --git a/gpsbabel/mkshort.c b/gpsbabel/mkshort.c index 8edef7683..fc3304ba1 100644 --- a/gpsbabel/mkshort.c +++ b/gpsbabel/mkshort.c @@ -287,22 +287,6 @@ mkshort(void *h, const char *istring) ostring = nstring; } - /* - * Look at the back of the string for " by BLAH" and whack - * it there. - */ - nstring = xxstrdup(ostring, file, line); - l = strlen (nstring); - while (l > 0) { - if (case_ignore_strncmp(&nstring[l], " by ",4) == 0) { - nstring[l] = 0; - break; - } - l --; - } - xfree(ostring); - ostring = nstring; - /* Eliminate leading whitespace in all cases */ while (ostring[0] && isspace(ostring[0])) { /* If orig string has N bytes, we want to copy N-1 bytes @@ -417,6 +401,32 @@ mkshort(void *h, const char *istring) return ostring; } +/* + * As above, but arg list is a waypoint so we can centralize + * the code that considers the alternate sources. + */ +char * +mkshort_from_wpt(void *h, const waypoint *wpt) +{ + /* This probably came from a Groundspeak Pocket Query + * so use the 'cache name' instead of the description field + * which contains placer name, diff, terr, and generally way + * more stuff than should be in any one field... + */ + if (wpt->gc_data.diff && wpt->gc_data.terr && wpt->notes) { + return mkshort(h, wpt->notes); + } + + if (wpt->description) { + return mkshort(h, wpt->description); + } + + if (wpt->notes) { + return mkshort(h, wpt->notes); + } +} + + #if 0 char *foo[] = { "VwthPst# 3700.706N 08627.588W 0000000m View the Past #2 ", diff --git a/gpsbabel/ozi.c b/gpsbabel/ozi.c index 4debbb81d..d9471e5cd 100644 --- a/gpsbabel/ozi.c +++ b/gpsbabel/ozi.c @@ -626,7 +626,7 @@ ozi_waypt_pr(const waypoint * wpt) if ((!wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { if (global_opts.synthesize_shortnames) - shortname = mkshort(mkshort_handle, wpt->description); + shortname = mkshort_from_wpt(mkshort_handle, wpt); else shortname = csv_stringclean(wpt->description, ","); } else { diff --git a/gpsbabel/palmdoc.c b/gpsbabel/palmdoc.c index cda37d95b..5e82f5aea 100644 --- a/gpsbabel/palmdoc.c +++ b/gpsbabel/palmdoc.c @@ -423,13 +423,13 @@ palmdoc_disp(const waypoint *wpt) char bookmarktext[17]; if ( bmid ) { - char * s = mkshort(mkshort_bookmark_handle, wpt->description); + char * s = mkshort_from_wpt(mkshort_bookmark_handle, wpt); sprintf( bookmarktext, "%6s:%9s", wpt->shortname?wpt->shortname:"",s); xfree(s); } else { - char * s = mkshort(mkshort_bookmark_handle, wpt->description); + char * s = mkshort_from_wpt(mkshort_bookmark_handle, wpt); sprintf( bookmarktext, "%16s", s); xfree(s); } @@ -448,7 +448,7 @@ palmdoc_disp(const waypoint *wpt) strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); docprintf(300, "%-16s %c%d %06.3f %c%d %06.3f (%ld%c %6.0f %7.0f)", - (global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname, + (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint), utmz, utmzc, utme, utmn); diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index 132c1690d..fb4f87276 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -194,7 +194,7 @@ gpsutil_disp(const waypoint *wpt) fprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e %d\n", global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, wpt->description) : + mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, lat < 0.0 ? 'S' : 'N', fabs(lat), diff --git a/gpsbabel/psp.c b/gpsbabel/psp.c index c621be61e..b3a04e650 100644 --- a/gpsbabel/psp.c +++ b/gpsbabel/psp.c @@ -327,7 +327,7 @@ psp_waypt_pr(const waypoint *wpt) if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { if (global_opts.synthesize_shortnames) - shortname = mkshort(mkshort_handle, wpt->description); + shortname = mkshort_from_wpt(mkshort_handle, wpt); else shortname = xstrdup(wpt->description); } else { diff --git a/gpsbabel/text.c b/gpsbabel/text.c index a80761b7d..56b272c76 100644 --- a/gpsbabel/text.c +++ b/gpsbabel/text.c @@ -82,7 +82,7 @@ text_disp(const waypoint *wpt) strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); fprintf(file_out, "%-16s %c%d %06.3f %c%d %06.3f (%ld%c %6.0f %7.0f)", - (global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname, + (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint), utmz, utmzc, utme, utmn); diff --git a/gpsbabel/tmpro.c b/gpsbabel/tmpro.c index 2e1ed9a98..4940f20cc 100644 --- a/gpsbabel/tmpro.c +++ b/gpsbabel/tmpro.c @@ -180,7 +180,7 @@ tmpro_waypt_pr(const waypoint * wpt) if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { if (global_opts.synthesize_shortnames) - shortname = mkshort(mkshort_handle, wpt->description); + shortname = mkshort_from_wpt(mkshort_handle, wpt); else shortname = csv_stringclean(wpt->description, ",\""); } else { diff --git a/gpsbabel/tpg.c b/gpsbabel/tpg.c index e12807d86..c30dec255 100644 --- a/gpsbabel/tpg.c +++ b/gpsbabel/tpg.c @@ -225,7 +225,7 @@ tpg_waypt_pr(const waypoint *wpt) if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { if (global_opts.synthesize_shortnames) - shortname = mkshort(mkshort_handle, wpt->description); + shortname = mkshort_from_wpt(mkshort_handle, wpt); else shortname = xstrdup(wpt->description); } else { -- 2.30.2